package pers.lance.firstweb.servlet;

import pers.lance.firstweb.dao.UserManager;
import pers.lance.firstweb.dao.UserManagerImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "LoginServlet", urlPatterns = "/login")
public class LoginServlet extends UserInterceptServlet {
    UserManager userManager = new UserManagerImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String name = request.getParameter("name");
        String password = request.getParameter("password");

        if ("admin".equals(name) && "123".equals(password)) {
            request.getSession().setAttribute("login_status", "logined");
            if (session.getAttribute("usercache") != null) {
                response.sendRedirect("/adduser");
            } else {
                response.sendRedirect("/index.html");
            }
        } else {
            response.getWriter().write("账号或密码错误");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
